#!/bin/bash

# function delete route
# if route $1 dev $2 exists, delete it
# $1: destination
# $2: dev
# $3: table name default: main
function delete_route() {
        local destination=$1
        local dev=$2
        local table_name=$3
        if [ -z "$table_name" ]; then
                table_name="main"
        fi
        local route=$(ip route show table $table_name | grep $destination | grep $dev)
        if [ -n "$route" ]; then
                echo "Delete route $destination dev $dev"
                ip route del $destination dev $dev table $table_name
        fi
}

delete_route 0.0.0.0/1 tun1
delete_route 128.0.0.0/1 tun1

